package zhishuang.wang.sansi.x9.plantask;

/**
 * @Author Zhishuang.Wang
 * @Date 2023/7/5 11:23
 * @Email 1406110602@qq.com
 */

import zhishuang.wang.sansi.tools.ReturnData;
import zhishuang.wang.sansi.tools.time.DateFormat;
import java.util.List;

public class PlanInfor {
    private String planId;
    private String planToken;
    private String startTime;
    private String endTime;
    private List<PlanItemInfor> itemList;

    public PlanInfor() {
    }

    public ReturnData checkParam() {
        ReturnData rd = new ReturnData();
        String errMessage = "";
        if (this.planId == null || this.planId.length() == 0) {
            errMessage = errMessage + "计划ID必填\n";
        }

        if (this.itemList != null && this.itemList.size() != 0) {
            if (this.itemList.size() > 10) {
                errMessage = errMessage + "计划项最多支持10条\n";
            } else {
                ReturnData checkRd = null;

                for(int i = 0; i < this.itemList.size(); ++i) {
                    PlanItemInfor item = (PlanItemInfor)this.itemList.get(i);
                    checkRd = item.checkParam();
                    if (checkRd.getCode() != 0) {
                        errMessage = errMessage + "计划项ID（" + item.getItemId() + "）错误信息：\n" + checkRd.getMessage();
                    }
                }
            }

            if (this.startTime != null && this.startTime.length() != 0) {
                if (this.startTime.length() != 14) {
                    errMessage = errMessage + "计划开始时间格式错误，格式为：YYYYMMDDHHMMSS\n";
                }
            } else {
                this.startTime = "20210101000000";
            }

            if (this.endTime != null && this.endTime.length() != 0) {
                if (this.endTime.length() != 14) {
                    errMessage = errMessage + "计划结束时间格式错误，格式为：YYYYMMDDHHMMSS\n";
                }
            } else {
                this.endTime = "23000101000000";
            }
        } else {
            errMessage = errMessage + "计划项必填\n";
        }

        if (errMessage.length() > 1) {
            rd.setMessage(errMessage);
        } else {
            rd.setCode(0);
        }

        rd.setTime(DateFormat.getNowDataFormat());
        return rd;
    }

    public String getPlanId() {
        return this.planId;
    }

    public void setPlanId(String planId) {
        this.planId = planId;
    }

    public String getPlanToken() {
        return this.planToken;
    }

    public void setPlanToken(String planToken) {
        this.planToken = planToken;
    }

    public String getStartTime() {
        return this.startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return this.endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public List<PlanItemInfor> getItemList() {
        return this.itemList;
    }

    public void setItemList(List<PlanItemInfor> itemList) {
        this.itemList = itemList;
    }
}
